<template>
  <div>
    <home-header></home-header>
    <home-swiper :list="swiperList"></home-swiper>
    <home-icons :list="iconList"></home-icons>
    <home-recommend :list="recommendList"></home-recommend>
    <home-footer></home-footer>
    <!--使用头部组件，HomeHeader是大写的，但是在vue中，vue会自动把大小写字母做上关联-->
  </div>
</template>
<script>
import HomeHeader from './conponents/Header'
import HomeSwiper from './conponents/Swiper'
import HomeIcons from './conponents/Icons'
import HomeRecommend from './conponents/Recommend'
import HomeFooter from './conponents/Footer'
import axios from 'axios'
export default {
  name: 'Home',
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcons,
    HomeRecommend,
    HomeFooter
  },
  data () {
    return {
      swiperList: [],
      iconList: [],
      recommendList: []
    }
  },
  methods: {
    getHomeInfo () {
      axios.get('/api/test.json')
        .then(this.getHomeInfoSucc)
    },
    getHomeInfoSucc (res) {
      res = res.data
      if (res.ret && res.data) {
        const data = res.data
        this.swiperList = data.swiperList
        this.iconList = data.iconList
        this.recommendList = data.recommendList
        console.log(res)
      }
      // 当ajax获取到数据之后，拿到数据的内容
      // 如果后端正确返回了结果，而且里面有data这个内容
    }
  },
  mounted () {
    this.getHomeInfo()
  }
}
</script>

<style>

</style>
